<%@ page language="java" import="java.util.*" pageEncoding="utf-8"
	isELIgnored="false"%>
<%@page import="com.flute.search.bean.*"%>
<%@taglib prefix="c" uri="http://java.sun.com/jstl/core"%>
<%@ page buffer="100kb"%>
<%
	String path = request.getContextPath();
%>
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>接口返回结果</title>
		<link href="<%=path%>/css/form.css" rel="stylesheet" type="text/css" />
		<link href="<%=path%>/css/font.css" rel="stylesheet" type="text/css" />
		<link href="<%=path%>/css/displaytag.css" rel="stylesheet"
			type="text/css" />
		<script type="text/javascript" src="common/prefixTips.js"></script>
		<script type="text/javascript" src="js/common.js"></script>
		<script type="text/javascript">
			function _$(id){
			    return document.getElementById(id);	
			}
			window.onload = function(){
				initPrefixTips("<%=path%>");
				<%
				if(request.getAttribute("record") != null){
					DataRecordField record = (DataRecordField)request.getAttribute("record");
					Set<String> fields = record.getFields();
					out.print("var field_count = " + fields.size() + ";");
					out.print("var record_count = " + record.getValues().size() + ";");
					out.print("var fields = new Array(");
					int i=0;
					for(Iterator<String> it = record.getFields().iterator();it.hasNext();){					
						out.print("'"+it.next()+"'");
						if(i<fields.size()-1){
							out.print(",");
						}
						i++;
					}
					out.print(");");
					%>
					var max = new Array();
					for(var i=0;i<record_count;i++){
						for(var j=0;j<field_count;j++){
							var field = fields[j];
							var td = document.getElementById("field_td_"+i+"_"+j);	
							if(i==0){
								max[j] = fields[j].length;	
							}		
							if(td.innerHTML.length >　max[j]){
								max[j] = td.innerHTML.length;
							}
						}
					}
					var all_length = 0;
					for(var i=0;i<max.length;i++){
						all_length += max[i];
					}
					var temp = "";
					var clientWidth = document.body.clientWidth * 0.96;
					for(var i=0;i<field_count;i++){				
						var th = document.getElementById("field_th_"+i);
						th.style.width = clientWidth*(max[i]/all_length)+"px";
						temp += th.style.width + ",";
					}
				<%}%>
				
				//设定搜索器的值
				var options = _$("searcher").options;
				for(var i =0;i<options.length;i++){
					if(options[i].value == "${param.searcher }"){
						options[i].selected = true;
						break;
					}
				}
			}
			function checkForm(){
				var sear = document.getElementsByName("searcher")[0];
				if(sear.value==""){
					alert("请选择搜索器");
					sear.focus();
					return false;
				}
				if(_$("keyword").value==""){
					alert("请输入关键词");
					_$("keyword").focus();
					return false;
				}
				if(!checkNumber(_$("num"))){
					return false;
				}
				return true;
			}
			function checkNumber(object){
				var value = object.value;
				var type=new RegExp("^[1-9][0-9]*$");
				if(value.length==0 || value.match(type)==null){
			 		alert("请输入一个正整数！");
			 		object.focus();object.select();
			 		return false;
			 	}
			 	return true;
			}
			function search(){
				if(checkForm()){
					document.listForm.page.value = 1;
					return true;
				}
				return false;
			}
		</script>
	</head>

	<body>
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
			<tr>
				<td width="2%">
					&nbsp;
				</td>
				<td width="96%" valign="top">
					<table width="100%" border="0" cellspacing="0" cellpadding="0">
						<tr>
							<td height="39" style="border-bottom: 1px dotted #ccc;">
								<br>
								<form method="get" name="listForm" id="listForm"
									action="viewSearch" onsubmit="return search();">
									<input type="hidden" name="page" value="${param.page }" />
									<input type="hidden" name="sorter" value="1" />
									&nbsp;&nbsp;搜索器:
									<select id="searcher" name="searcher">
										<c:forEach var="search" items="${searches}">
											<option value="${search.value }">
												${search.name }
											</option>
										</c:forEach>
									</select>
									&nbsp;&nbsp;关键词:
									<input id="keyword" name="keyword" value="${param.keyword }" />
									&nbsp;&nbsp;每页显示的条数:
									<input id="num" name="num" value="${param.num }"
										style="width: 50px" />
									&nbsp;&nbsp;显示全部字段:
									<c:choose>
										<c:when test="${!empty param.showAll && param.showAll==1}">
											<input type="checkbox" name="showAll" value="1"
												checked="checked" />
										</c:when>
										<c:otherwise>
											<input type="checkbox" name="showAll" value="1" />
										</c:otherwise>
									</c:choose>
									&nbsp;&nbsp;
									<input type="submit" value="搜索" />
								</form>
							</td>
						</tr>
					</table>
					<c:if test="${!empty record}">
						<c:choose>
							<c:when test="${empty record.values}">
								<table width="100%" border="0" cellspacing="0" cellpadding="0">
									<tr>
										<td align="center" height="25">
											对不起，没有找到相关记录！
										</td>
									</tr>
								</table>
							</c:when>
							<c:otherwise>
								<table width="100%" border="0" cellspacing="0" cellpadding="0">
									<tr>
										<td height="30">
											<strong class="titletop"> <c:forEach var="cap"
													items="${caption}">
													&nbsp;${cap }
												</c:forEach> </strong>
										</td>
									</tr>
								</table>
								<table width="100%">
									<tr>
										<td>
											<table id="item" width="100%" cellpadding="0"
												class="displaytag_css" border="0" cellspacing="1"
												bgcolor="cccccc">
												<thead>
													<tr>
														<c:forEach var="field" items="${record.fields}"
															varStatus="s">
															<th id="field_th_${s.index }" align="center"
																style="width: 500px;">
																${field }
															</th>
														</c:forEach>
													</tr>
												</thead>
												<tbody>
													<c:forEach var="row" items="${record.values}" varStatus="s">
														<c:if test="${s.index%2==0}">
															<tr class="odd">
														</c:if>
														<c:if test="${s.index%2==1}">
															<tr class="even">
														</c:if>
														<c:forEach var="value" items="${row}" varStatus="ss">
															<td align="center" id="field_td_${s.index }_${ss.index }"
																style="white-space: normal; word-break: break-all;">
																${value }
															</td>
														</c:forEach>
														</tr>
													</c:forEach>
												</tbody>
											</table>
											<table width="100%" border="0" cellpadding="3"
												cellspacing="0" class="yema">
												<tr>
													<td align="center">
														<jsp:include page="/common/dataPager.jsp"></jsp:include>
													</td>
												</tr>
											</table>
										</td>
									</tr>
								</table>
							</c:otherwise>
						</c:choose>
					</c:if>
				</td>
				<td width="2%">
					&nbsp;
				</td>
			</tr>
		</table>
	</body>
</html>
